package code;

import java.util.Random;

public class Main {
    public static void main(String[] args) {
        System.out.println("验证码为"+createcode(5));
    }
    public static String createcode(int n) {

        String code = null;
        code = "";
        for (int i = 0; i < n; i++) {
            Random random = new Random();
            int num = random.nextInt(3);//0 1 2
            switch (num) {
                case 1://大写
                {
                    char ch = (char) (random.nextInt(26) + 65);
                    code += ch;
                    break;
                }
                case 2://小写
                {
                    char ch = (char) (random.nextInt(26) + 97);
                    code+=ch;
                    break;
                }
                case 0://数字
                {
                    code += random.nextInt(10);
                    break;
                }
            }
        }
        return code;
    }
}
